package com.c.ctgproject.ui.doorkeeper.car

import com.c.ctgproject.base.BasePresenter
import com.c.ctgproject.entity.ListCarWaitingEntrance
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MvpObserver
import com.c.ctgproject.http.ObserverListener
import com.c.ctgproject.utils.MyLog
import com.google.gson.Gson
import okhttp3.ResponseBody

/**
 *作者:LiBW
 *创建日期: 2020/8/15
 *描述: 门卫Presenter
 */
class CarWaitPresenter : BasePresenter<CarWaitContract.View>(), CarWaitContract.Presenter {
    //获取待入场车辆信息
    override fun getCarsInfo(page: Int, size: Int, plateNum: String, showLoading: Boolean?) {
        val carsInfoListener = object : ObserverListener {
            override fun onNext(t: ResponseBody) {
                val data = t.string().toString()
                MyLog.d("门卫待入场车辆$data")
                mView?.carsInfoResult(Gson().fromJson(data, ListCarWaitingEntrance::class.java))
            }

            override fun onError(error: String) {
                MyLog.d(error)
                mView?.onError(error)
            }
        }
        if (showLoading != null) {
            ApiMethods.listCarWaitingEntrance(MvpObserver(carsInfoListener, mView, showLoading), page, size, plateNum)
        } else {
            ApiMethods.listCarWaitingEntrance(MvpObserver(carsInfoListener, mView), page, size, plateNum)
        }

    }


}